import { storageLocal } from "@/utils/storage";
import type { Module } from 'vuex'
import type { AppState } from "../types";

const appModule: Module<AppState,any> = {
  namespaced: true,
  state: {
      sidebar:{
          opened:storageLocal.getItem("sidebarStatus")===0 ? false : true,
          hidden:storageLocal.getItem("hiddenSidebar")===0||storageLocal.getItem("hiddenSidebar")===null ? false : true,
      },
  },
  mutations:{
      TOGGLE_SIDEBAR:(state)=> {
          state.sidebar.opened = !state.sidebar.opened;
          if (state.sidebar.opened) {
            storageLocal.setItem("sidebarStatus", 1);
          } else {
            storageLocal.setItem("sidebarStatus", 0);
          }
      },
      CHANGE_SIDEBAR:(state,data)=>{
        state.sidebar.hidden = data.value;
        if (state.sidebar.hidden) {
          storageLocal.setItem("hiddenSidebar", 1);
        } else {
          storageLocal.setItem("hiddenSidebar", 0);
        }
      }
  },
  actions: {
      toggleSideBar({commit}) {
          commit('TOGGLE_SIDEBAR');
      },
      changeSidebar({commit},data) {
        commit('CHANGE_SIDEBAR',data);
      }
  }
};
export default appModule